package com.apress.springrecipes.sequence;

import java.util.HashMap;
import java.util.Map;

import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;
@Repository
public class SequenceDaoImpl implements SequenceDao {
	private Map<String, Sequence> sequences;
	private Map<String,Integer> values;
	
	public SequenceDaoImpl(){
		sequences = new HashMap<String,Sequence>();
		sequences.put("IT", new Sequence("30","IT","A"));
		values = new HashMap<String,Integer>();
		values.put("IT", 100000);
	}
	@Override
	public Sequence getSequence(String sequenceId) {
		// TODO Auto-generated method stub
		return sequences.get(sequenceId);
	}
	
	@Override
	public synchronized int getNextValue(String sequenceId) {
		int value = values.get(sequenceId);
		values.put(sequenceId, value + 1);
		return value;
	}

}
